from django.http import JsonResponse
# Create your views here.
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response

from userprofile.models import Checker
from userprofile.serializers import checkerListSerializer


@api_view(['GET', 'POST'])
def login(request):
    if request.method == "GET":
        checker = Checker.objects.all()
        serializer = checkerListSerializer(checker, many=True)
        return Response(serializer.data)
    elif request.method == "POST":
        serializer = checkerListSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data,status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)